<?php
class DetailItemRender
{
  static public function render($conf)
  {
    switch($conf["form_item_type"])
    {
      case "radio":
      case "select":
        $renderMethod = "singleSelect";
        break;
      case "checkbox":
      case "multiple_select":
        $renderMethod = "multipleSelect";
        break;
      default:
        $renderMethod = "text";
    }
    echo "\n<div><label>" . $conf["caption"] . "</label>";
    if (isset($conf["user_value"]))
    {
    	self::$renderMethod($conf);
    }
    echo !empty($conf["tips_for_reader"]) ? '<span class="tips">（' . $conf["tips_for_reader"] . "）</span>" : "";
    echo "</div>";
  }
  
  static public function singleSelect($conf)
  {
    foreach ($conf["options"] as $option)
    {
      if ($conf["user_value"] == $option["option_index"])
      {
        echo $option["option_text"];
        break;
      }
    }
  }
  
  static public function multipleSelect($conf)
  {
    foreach ($conf["options"] as $option)
    {
      if (in_array($option["option_index"], $conf["user_value"]))
      {
        echo $option["option_text"] . "  ";
      }
    }
  }
  
  static public function text($conf)
  {
      echo $conf["user_value"] . "  ";
  }
}
